import 'device_model.dart';
import 'package:wanke/function.dart';
import 'dart:async';
class GroupModel{
  String name;
  int id;
  List<DeviceModel> devices;
//  double yesterdayIncome=0.0;
//  double prevdayIncome=0.0;
  bool showDevice=true;
  GroupModel({this.id,this.name,this.devices});

  double get yesterdayIncome{
    double income=0.0;
    this.devices.forEach((device){
      income+=device.yesterday_income;
    });
    return income;
  }
  double get prevdayIncome{
    double income=0.0;
    this.devices.forEach((device){
      income+=device.prevday_income;
    });
    return income;
  }
  double get balanceIncome{
    double income=0.0;
    this.devices.forEach((device){
      income+=device.balance_income;
    });
    return income;
  }
  double get totalIncome{
    double income=0.0;
    this.devices.forEach((device){
      income+=device.total_income;
    });
    return income;
  }
  Future<bool> update() async{
    return await updateGroup(this.id, this.name);
  }
}
List<GroupModel> groups=[];
String price="获取中";
double get yesterdayIncome{
 double income=0.0;
 for(var i=0;i<groups.length;i++){
   income+=groups[i].yesterdayIncome;
 }
 return income;
}
double get prevdayIncome{
  double income=0.0;
  for(var i=0;i<groups.length;i++){
    income+=groups[i].prevdayIncome;
  }
  return income;
}
double get avgIncome{
  var income = yesterdayIncome/deviceCount;
  return income;
}
double get balanceIncome{
  double income=0.0;
  for(var i=0;i<groups.length;i++){
    income+=groups[i].balanceIncome;
  }
  return income;
}
double get totalIncome{
  double income=0.0;
  for(var i=0;i<groups.length;i++){
    income+=groups[i].totalIncome;
  }
  return income;
}
int deviceCount = 0;
String loginAccount = "";
String loginPassword = "";
String loginGroup = "默认分组";
String addGroupName = "";